package jmu.cyxwcy.librarymanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jmu.cyxwcy.librarymanagement.pojo.Classes;
import jmu.cyxwcy.librarymanagement.mapper.ClassesMapper;
import jmu.cyxwcy.librarymanagement.pojo.College;
import jmu.cyxwcy.librarymanagement.service.IClassesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jmu.cyxwcy.librarymanagement.service.IMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-06-26
 */
@Service
public class ClassesServiceImpl extends ServiceImpl<ClassesMapper, Classes> implements IClassesService {

    @Autowired
    private IMajorService iMajorService;
    @Override
    public List<Classes> findByCollegeNamPartial(String classNamePartial) {
        QueryWrapper<Classes> queryWrapper = new QueryWrapper<>();
        queryWrapper.likeRight("class_name",classNamePartial);
        return list(queryWrapper);
    }
    @Override
    public List<Classes> findByMajorName(String majorName, String classNamePartial) {
        Integer majorId=iMajorService.findIdByMajorName(majorName);
        QueryWrapper<Classes> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("major_id", majorId)
                .likeRight("class_name", classNamePartial);
        return list(queryWrapper);
    }

    @Override
    public Classes getClassByName(String className) {
        QueryWrapper<Classes> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("class_name", className);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<Classes> findByMajorId(Integer majorId) {
        QueryWrapper<Classes> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("major_id", majorId);
        return this.list(queryWrapper);
    }

}
